package com.cskaoyan._01abstractclazz._04ex;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/11 9:55
 **/

public class Demo {
    public static void main(String[] args) {
        BaseStaff staff;
        staff = new NormalStaff("zs", 1, 3000);
        staff.work();
        staff.print();

        staff = new Coder("ls", 2, 20000);
        staff.work();
        if (staff instanceof Coder) {
            ((Coder) staff).overTimeWork();
        }
        staff.print();

        staff = new Manager("ww", 3, 40000);
        if (staff instanceof Manager) {
            ((Manager) staff).bonus = 100000;

        }
        staff.work();
        staff.print();
    }
}

// 抽象员工类
abstract class BaseStaff{
    // 成员变量
    String name;
    int id;
    double salary;

    public BaseStaff(String name, int id, double salary) {
        this.name = name;
        this.id = id;
        this.salary = salary;
    }

    // 抽象方法work
    public abstract void work();

    // 输出员工信息
    public void print() {
        System.out.println("工号: " + id+" 姓名: " + name+
                " 工资: " + salary);
    }
}

// 程序员类
class Coder extends BaseStaff{

    @Override
    public void work() {
        System.out.println("我喜欢写代码!");
    }

    public Coder(String name, int id, double salary) {
        super(name, id, salary);
    }

    // 子类中独有的方法
    public void overTimeWork() {
        System.out.println("996福报,就喜欢加班,公司是我家,浪费公司电,浪费公司水");

    }
}

class NormalStaff extends BaseStaff{
    public NormalStaff(String name, int id, double salary) {
        super(name, id, salary);
    }

    @Override
    public void work() {
        System.out.println("我为牛马,打杂!");
    }
}

class Manager extends BaseStaff{
    // 子类中独有的属性
    double bonus;

    public Manager(String name, int id, double salary) {
        super(name, id, salary);
    }

    @Override
    public void work() {
        System.out.println("看着你们干活真开心,反正我5点下班!");
    }

    @Override
    public void print() {
        System.out.println("工号: " + id+" 姓名: " + name+
                " 工资: " + salary+" 奖金: " + bonus);
    }
}